<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      /* 
      思路：后序遍历，获取每个节点的最大路径和 然后返回当前节点
      */
      var maxPathSum = function (root) {
        let res = root.val
        function postOrder(root) {
          if (!root) return 0
          let left = postOrder(root.left)
          let right = postOrder(root.right)
          res = Math.max(res, left + right + root.val)
          let maxSum = Math.max(left, right) + root.val
          return root.val > 0 ? root.val : 0
        }
      }
    </script>
  </body>
</html>
